package com.springboot.contorller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

/**
 * @Description
 * @Author 顾志杰
 * @Date 2021/11/3 11:06
 */
@RestController
public class OnController {
    @GetMapping("hello")
    public String hello(HttpServletRequest request, HttpServletResponse response){
        Cookie[] cookieList = request.getCookies();

        String retValue = null;
        try {
            for (Cookie cookie : cookieList) {
                if (cookie.getName().equals("name")) {

                    retValue = URLDecoder.decode(cookie.getValue(), "UTF-8");

                    break;
                }
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return retValue;
    }
}
